import { CommonModal } from '@/pages/OrderModule/common/components/CommonModal';
import CommonInput from '@/pages/OrderModule/common/components/CommonInput';
import { Button, Form, Modal, Row, Col } from 'antd';
import { find } from 'lodash';
import { useEffect, useRef, useState } from 'react';
import GoodsFilterForm from './GoodsFilterForm';
import GoodsShowTable from './GoodsShowTable';
import { TableType } from './helpers/constant';

import GoodsListModal from '@/pages/GoodsModule/combinationGoods/component/GoodsListModal'


/**
 *
 * type字段 选择商品组件组件分别是
    1. 新增商品（无数量）：即无数量的输入框
    2. 新增商品（有数量）：即有数量的输入框
    3. 新增款式商品：统一无数量，只是选择一整个款
 */
const GoodsSelectModal = (props) => {
    const { children, setSelectedRows = () => [], submitCallback, handleSubmitAllInfo, getInputNumberValues, title = '新增商品', handleCancel, isSingle, node, showCustomizeGoods = false, selectName = 'add', hiddenGoodNum = false, selectTitle = '', hiddenExtra = false } = props;
    if (typeof submitCallback !== 'function') {
        throw new Error('submitCallback is required');
    }

    const [show, toggleShow] = useState(false);
    const btn = children || <Button>新增商品</Button>;
 
		useEffect(() => {
			handleCancel && toggleShow(true);
		}, [])
    
    const openModal = () => {
        toggleShow(true);
    };
 
    const modalProps = {
        style: { position: 'absolute', top: 72, left: 0, right: 0, margin: 'auto' },
		handleCancel() {
			toggleShow(false);
            handleCancel && handleCancel();
		},
        onGoodsSkuListSelected(values, isCustom) {
            submitCallback(values, isCustom)
            
        },
        destroyOnClose: true,
        showCustomizeGoods,
        selectName,
        selectTitle,
        hiddenGoodNum,
        hiddenExtra
	};

    return (<>
      <span onClick={openModal}>{btn}</span>
      {show ? <GoodsListModal {...modalProps}/> : null}
    </>);
};
export default GoodsSelectModal;
